package com.yykj.backstage.all.converter;

import com.yykj.backstage.all.dto.AdminRoleDTO;
import com.yykj.backstage.all.model.entity.AdminRole;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class AdminRoleDTOConverter {
    public static AdminRoleDTO convert(AdminRole role) {
        AdminRoleDTO d = new AdminRoleDTO();
        BeanUtils.copyProperties(role,d);
        if(StringUtils.isEmpty(role.getOauthIds())){
            d.setOauthIds(new ArrayList<>());
        }else{
            d.setOauthIds(Arrays.asList(role.getOauthIds().split(",")));
        }
        return d;
    }

    public static List<AdminRoleDTO> convert(List<AdminRole> list){
        return list.stream().map(AdminRoleDTOConverter::convert).collect(Collectors.toList());
    }
}
